angular.module('nm.controller', 
  [
  'nm.service',
  'ui.bootstrap'
  ])
// 侧边菜单
.controller('SideBarCtrl', ['$scope', '$location', 
function($scope,$location) {
    $scope.menus = [
        {label:'监控列表','href':'#/monitor/list', actived:true},
        {label:'告警设置','href':'#/alarm/list'},
        {label:'监控日志','href':'#/logs/list'}
    ];

    $scope.goto = function(menu){
      $scope.menus.forEach(function (e){
        e.actived = false;
      });
      menu.actived = true;
    };
}])
// 顶部导航栏
.controller('NavCtrl', ['$scope', '$location', 
function($scope,$location) {

}])
//监控相关
.controller('MonitorListCtrl', [
    '$scope','$location', 'Monitors', function($scope, $location, Monitors) {

      Monitors.getMonitors({}, function (result){
        $scope.monitors = result;
      });
}])
.controller('MonitorCreateCtrl', [
    '$scope','$location', function($scope,$location) {

    $scope.monitor = {
      interval: 18000,
      timeout: 10000,
      autoStart: 'true',
      valid: {
        code: 200,
        method: 'HEAD'
      },
      alarm: {
        'continue': 5,
        users:[
          {id:'11999', name:'当前用户'},
        ]
      }
      
    };




    $scope.loadTags = function(){
      return [
        {id:'111111', name:'张大夫'},
        {id:'2222222222',name:'李大夫'},
        {id:'4344444444', name:'欧阳大夫'},
        {id:'333333333333', name:'郭大侠'},
        {id:'555555555',name:'杨少侠'},
        {id:'00000000', name:'耶律少侠'}
      ];
    };

    $scope.confirm = function(){
      console.log($scope.monitor);
    }
}])
//告警相关
.controller('AlarmListCtrl', [
    '$scope','$location', 'Users', function($scope, $location, Users) {  
    Users.get({}, function(r){
      $scope.users = r.result.users;
    }); 
}])
.controller('AlarmUserCreateCtrl', [
    '$scope','$location', 'Users', function($scope, $location, Users) {  
    $scope.user = {
      groups: []
    };    



    $scope.loadGroups = function(){
      return   [
        {id:'111111', name:'张大夫组'},
        {id:'2222222222',name:'李大夫组'},
        {id:'4344444444', name:'欧阳大夫组'},
        {id:'333333333333', name:'郭大侠组'}
      ]
    };

    $scope.confirm = function(){
      var u = $scope.user;
      u.groups = [];
      $scope.user.groups.forEach(function(e){
        u.groups.push(e.id);
      });

      Users.add(u, function(r){
        if(r.code == 200){
          $location.url('/alarm/list');
        }
      });
    };
}])
//日志相关
.controller('LogsListCtrl', [
    '$scope','$location', function($scope,$location) {  
}])

//end
;



